home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Very Best of Atari Inside
/
The Very Best of Atari Inside 1.iso
/
mint
/
mntlib43
/
mntlib
/
sync.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-09
|
2KB
|
124 lines
/*
* FILE
* sync.c
*
*
* DESCRIPTION
* syncing filesystems, makes only sense with mint and
* minixfs for now
*
* BUGS
* minixfs V 060 PL 5 always syncs all drives, so there will
* be too much syncing, since we call Dcntl for all known drives.
*
*/
#include <mintbind.h>
#include <stat.h>
#include <errno.h>
#include <support.h>
extern int __mint;
/* from minixfs.h by S N Henson*/
#define MFS_BASE 0x100
#define MFS_VERIFY (MFS_BASE) /* Return minixfs magic number */
#define MFS_SYNC (MFS_BASE|0x01) /* Sync the filesystem */
#define MFS_MAGIC 0x18970431 /* Magic number from MFS_VERIFY */
/*
* FUNCTION
* int sync(void)
*
* DESCRIPTION
* query all known drives for a valid MinixFs
* if we find one, sync it.
*/
int sync(void)
{
long magic;
unsigned long drives;
int i, rv;
char path[] = "A:\\";
if (!__mint)
return 0;
drives = Dsetdrv(Dgetdrv());
drives &= ~0x3; /* don't sync the floppys */
for (i = 2; drives ; i++) {
if (drives & (1L << i)) {
drives &= ~(1L << i);
path[0] = 'A' + i;
magic = 0L;
if (!Dcntl(MFS_VERIFY, path, &magic) && magic == MFS_MAGIC) {
if ((rv = (int)Dcntl(MFS_SYNC, path, 0L)) < 0) {
errno = -rv;
return -1;
}
}
}
}
return 0;
} /* sync() */
/*
* FUNCTION
* int fsync(int fd)
*
* DESCRIPTION
* sync all buffers related to file descriptor fd
* since MFS 605 always syncs all the buffers, we don't bother
* to get the full path.
*/
int fsync(fd)
int fd;
{
int rv;
long magic = 0L;
char path[] = "A:\\";
struct stat statbuf;
if (!__mint)
return 0;
if (fstat(fd, &statbuf))
return -1; /* errno set from fstat */
if (statbuf.st_dev >= 32)
/* If mounted via FS_MOUNT, st_dev will be > 0x100.
Pretend that it worked. */
return 0;
path[0] = 'A'+ statbuf.st_dev;
if (!Dcntl(MFS_VERIFY, path, &magic) && magic == MFS_MAGIC) {
if ((rv = (int)Dcntl(MFS_SYNC, path, 0L)) < 0) {
errno = -rv;
return -1;
}
}
return 0;
} /* fsync() */
#ifdef TEST
/*
* Im not in the mood to write a tricky test routine,
* so just do 'cat junk1 >junk2;sync' from your shell
* and listen to your harddisk.
*/
int main (void)
{
sync();
return 0;
}
#endif